package br.com.single.publico;

import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

@Entity
@Table(schema = "publico",name = "cdbanco")
@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "cdbanco", schema = "publico")
@RooDbManaged(automaticallyDelete = true)
public class Cdbanco {

	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "codigobanco",columnDefinition="codigonumero")
    private Integer codigobanco;
	
	
	@ManyToOne
    @JoinColumns({ @JoinColumn(name = "filialbanco", referencedColumnName = "codigofilial"), @JoinColumn(name = "ccustobanco", referencedColumnName = "codigoccusto") })
    private Cdccusto cdccusto;

	@ManyToOne
    @JoinColumn(name = "filialcontab", referencedColumnName = "codigofilial")
    private Cdfilial filialcontab;

	@Column(name = "nomebanco",columnDefinition="nomegrande")
    @NotNull
    private String nomebanco;

	@Column(name = "siglabanco",columnDefinition="nomegrande")
    @NotNull
    private String siglabanco;

	@Column(name = "codigoagenci", length = 10)
    private String codigoagenci;

	@Column(name = "descriagenci",columnDefinition="nomegrande")
    private String descriagenci;

	@Column(name = "numeroconta", length = 20)
    private String numeroconta;

	@Column(name = "cnab", length = 3)
    private String cnab;

	@Column(name = "instru01", length = 10)
    private String instru01;

	@Column(name = "instru02", length = 10)
    private String instru02;

	@Column(name = "saldoatual",columnDefinition="moeda")
    @NotNull
    private Double saldoatual;

	@Column(name = "endereagenci",columnDefinition="lograd")
    private String endereagenci;

	@Column(name = "codigoconven", length = 20)
    private String codigoconven;

	@Column(name = "sequenremess",columnDefinition="int4")
    private Integer sequenremess;

	@Column(name = "nossonumero")
    private Integer nossonumero;

	@Column(name = "limitecredit",columnDefinition="moeda")
    @NotNull
    private String limitecredit;

	@Column(name = "ctbcodigo",columnDefinition="codigocontab")
    private Integer ctbcodigo;

	@Column(name = "ctbapendi",columnDefinition="apendicontab")
    private Integer ctbapendi;

	@Column(name = "picturconta", length = 40)
    private String picturconta;

	public Cdccusto getCdccusto() {
        return cdccusto;
    }

	public void setCdccusto(Cdccusto cdccusto) {
        this.cdccusto = cdccusto;
    }

	public Cdfilial getFilialcontab() {
        return filialcontab;
    }

	public void setFilialcontab(Cdfilial filialcontab) {
        this.filialcontab = filialcontab;
    }

	public String getNomebanco() {
        return nomebanco;
    }

	public void setNomebanco(String nomebanco) {
        this.nomebanco = nomebanco;
    }

	public String getSiglabanco() {
        return siglabanco;
    }

	public void setSiglabanco(String siglabanco) {
        this.siglabanco = siglabanco;
    }

	public String getCodigoagenci() {
        return codigoagenci;
    }

	public void setCodigoagenci(String codigoagenci) {
        this.codigoagenci = codigoagenci;
    }

	public String getDescriagenci() {
        return descriagenci;
    }

	public void setDescriagenci(String descriagenci) {
        this.descriagenci = descriagenci;
    }

	public String getNumeroconta() {
        return numeroconta;
    }

	public void setNumeroconta(String numeroconta) {
        this.numeroconta = numeroconta;
    }

	public String getCnab() {
        return cnab;
    }

	public void setCnab(String cnab) {
        this.cnab = cnab;
    }

	public String getInstru01() {
        return instru01;
    }

	public void setInstru01(String instru01) {
        this.instru01 = instru01;
    }

	public String getInstru02() {
        return instru02;
    }

	public void setInstru02(String instru02) {
        this.instru02 = instru02;
    }

	public Double getSaldoatual() {
        return saldoatual;
    }

	public void setSaldoatual(Double saldoatual) {
        this.saldoatual = saldoatual;
    }

	public String getEndereagenci() {
        return endereagenci;
    }

	public void setEndereagenci(String endereagenci) {
        this.endereagenci = endereagenci;
    }

	public String getCodigoconven() {
        return codigoconven;
    }

	public void setCodigoconven(String codigoconven) {
        this.codigoconven = codigoconven;
    }

	public Integer getSequenremess() {
        return sequenremess;
    }

	public void setSequenremess(Integer sequenremess) {
        this.sequenremess = sequenremess;
    }

	public Integer getNossonumero() {
        return nossonumero;
    }

	public void setNossonumero(Integer nossonumero) {
        this.nossonumero = nossonumero;
    }

	public String getLimitecredit() {
        return limitecredit;
    }

	public void setLimitecredit(String limitecredit) {
        this.limitecredit = limitecredit;
    }

	public Integer getCtbcodigo() {
        return ctbcodigo;
    }

	public void setCtbcodigo(Integer ctbcodigo) {
        this.ctbcodigo = ctbcodigo;
    }

	public Integer getCtbapendi() {
        return ctbapendi;
    }

	public void setCtbapendi(Integer ctbapendi) {
        this.ctbapendi = ctbapendi;
    }

	public String getPicturconta() {
        return picturconta;
    }

	public void setPicturconta(String picturconta) {
        this.picturconta = picturconta;
    }

	

	public Integer getCodigobanco() {
        return this.codigobanco;
    }

	public void setCodigobanco(Integer id) {
        this.codigobanco = id;
    }

	@PersistenceContext
    transient EntityManager entityManager;

	public static final EntityManager entityManager() {
        EntityManager em = new Cdbanco().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	public static long countCdbancoes() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Cdbanco o", Long.class).getSingleResult();
    }

	public static List<Cdbanco> findAllCdbancoes() {
        return entityManager().createQuery("SELECT o FROM Cdbanco o", Cdbanco.class).getResultList();
    }

	public static Cdbanco findCdbanco(Integer codigobanco) {
        if (codigobanco == null) return null;
        return entityManager().find(Cdbanco.class, codigobanco);
    }

	public static List<Cdbanco> findCdbancoEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Cdbanco o", Cdbanco.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

	@Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	@Transactional
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Cdbanco attached = Cdbanco.findCdbanco(this.codigobanco);
            this.entityManager.remove(attached);
        }
    }

	@Transactional
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	@Transactional
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	@Transactional
    public Cdbanco merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Cdbanco merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }
}
